import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

public class App {
    public static void main(String[] args) throws JsonProcessingException {
        //1.创建一个json操作对象
        ObjectMapper objectMapper=new ObjectMapper();
        //2.1 将对象转换为json字符串
        Student student=new Student();
        student.setId(1);
        student.setName("Java");
        student.setPassword("123");
        String s = objectMapper.writeValueAsString(student);

        System.out.println(s);

        //2.2 将json字符串转换为对象
        String jsonStr="{\"id\":1,\"name\":\"Java\",\"password\":\"123\"}";
        Student student1=objectMapper.readValue(jsonStr,Student.class);
        System.out.println(student1);
    }
}

@Getter
@Setter
@ToString
class Student{
    private int id;
    private String name;
    private String password;
}